Fix waypoint output indexes when using multiple output files in xcsv and Topo!
authoralexmot <alexmot@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Wed, 23 Jul 2003 13:56:49 +0000 (13:56 +0000)
committeralexmot <alexmot@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Wed, 23 Jul 2003 13:56:49 +0000 (13:56 +0000)
gpsbabel/csv_util.c
gpsbabel/tpg.c

index c6014dc73d11b06e444953bf47f28c8a7e0e495b..f358626c2f0c0e9a3d1115971d66532a2dce927f 100644 (file)
@@ -37,6 +37,8 @@
 extern char *xcsv_urlbase;
 extern char *prefer_shortnames;
 
+static int waypt_out_count;
+
 /*********************************************************************/
 /* csv_stringclean() - remove any unwanted characters from string.   */
 /*                     returns copy of string.                       */
@@ -579,7 +581,6 @@ static void
 xcsv_waypt_pr(const waypoint *wpt)
 {
     char buff[1024];
-    static int index = 0;
     char *shortname = NULL;
     char *description = NULL;
     char * anyname = NULL;
@@ -633,7 +634,7 @@ xcsv_waypt_pr(const waypoint *wpt)
             sprintf(buff, fmp->printfc, "");
         } else
         if (strcmp(fmp->key, "INDEX") == 0) {
-            sprintf(buff, fmp->printfc, index + atoi(fmp->val));
+            sprintf(buff, fmp->printfc, waypt_out_count + atoi(fmp->val));
         } else
         if (strcmp(fmp->key, "CONSTANT") == 0) {
             sprintf(buff, fmp->printfc, fmp->val);
@@ -792,7 +793,8 @@ xcsv_waypt_pr(const waypoint *wpt)
     if (description && description != shortname)
         xfree(description);
 
-    index++;
+    /* increment the index counter */
+    waypt_out_count++;
 }
 
 static void
@@ -811,6 +813,9 @@ xcsv_data_write(void)
     queue *elem, *tmp;
     ogue_t *ogp;
 
+    /* reset the index counter */
+    waypt_out_count = 0;
+    
     /* output prologue lines, if any. */
     QUEUE_FOR_EACH(&xcsv_file.prologue, elem, tmp) {
         ogp = (ogue_t *) elem;
index 777638e6796a5cd8b59b02c2a0bcf7f6fc55ea30..ac62d1261968a1196f64da560ed022f2c102c781 100644 (file)
@@ -34,6 +34,7 @@ static void *mkshort_handle;
 
 static int i_am_little_endian;
 static int endianness_tested;
+static int waypt_out_count;
 
 static void
 test_endianness(void)
@@ -152,6 +153,8 @@ tpg_wr_init(const char *fname, const char *args)
        if (tpg_file_out == NULL) {
                fatal(MYNAME ": Cannot open %s for writing\n", fname);
        }
+       
+       waypt_out_count = 0;
 }
 
 static void
@@ -256,7 +259,6 @@ tpg_waypt_pr(const waypoint *wpt)
        char c;
        char *shortname;
        char *description;
-       static int out_count = 0;
 
         /* these unknown 4 are probably point properties (color, icon, etc..) */
        unsigned char unknown4[] = { 0x78, 0x56, 0x34, 0x12 }; 
@@ -265,7 +267,7 @@ tpg_waypt_pr(const waypoint *wpt)
        unsigned char unknown2[] = { 0x01, 0x80 };  
        
        /* our personal waypoint counter */
-       out_count++;
+       waypt_out_count++;
 
         /* this output format pretty much requires a description
          * and a shortname 
@@ -341,7 +343,7 @@ tpg_waypt_pr(const waypoint *wpt)
 
         /* and finally 2 unknown bytes */
         
-        if (out_count == waypt_count()) {
+        if (waypt_out_count == waypt_count()) {
                /* last point gets 0x0000 instead of 0x0180 */
                memset(tbuf, '\0', sizeof(tbuf));
                fwrite(tbuf, 1, 2, tpg_file_out);